#ifndef threading_Semaphore_h
#define threading_Semaphore_h

#ifdef WIN32
#else
# include <pthread.h>
# include <semaphore.h>
#endif
#include "ThreadConsts.h"
#include "Guard.h"

namespace serika
{
	namespace threading
	{
		class Semaphore
		{
		public:
			Semaphore(int initValue = 0);
			~Semaphore();
	
			LockState::Enum Acquire(long timeout = -1);		// timeout is in milliseconds
	
			LockState::Enum TryAcquire();
	
			void Release();
	
			typedef Guard<Semaphore> Guard;
		private:
	#ifdef WIN32
			void* mSem;
	#else
			sem_t mSem;
	#endif
		};
	}
}

#endif
